package com.dayatang.android.Activity;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.graphics.drawable.Drawable;

import com.dayatang.android.map.SubOverItem;
import com.google.android.maps.GeoPoint;

public class SubprojectMapActivity extends MapBaseActivity {
    
	protected void InitData() {
		try {
			String url = getServerAddress() + "/remote/subproject-site.action?username=" + getUsername();
			String data = getDataByUrl(url);
			if (data != null) {
				JSONArray jsonArray = new JSONArray(data);
				List<String> subProjData = new ArrayList<String>();
				
				for (int i = 0 ,len = jsonArray.length();i < len ; i++) { 
					JSONObject jsonObject = jsonArray.getJSONObject(i); 
					subProjData.add(jsonObject.toString());
					GeoPoint geoPoint = new GeoPoint((int)(jsonObject.getDouble("latitude")*1E6),(int)(jsonObject.getDouble("longitude")*1E6));
					
					mapController.setZoom(13);
					mapController.animateTo(geoPoint);
					
					geoPoints.add(geoPoint);
				}
				Drawable marker = getResources().getDrawable(R.drawable.point_start); 
				marker.setBounds(0, 0, marker.getIntrinsicWidth(), marker.getIntrinsicHeight());   //为maker定义位置和边界
				overlays.add(new SubOverItem(marker,this,geoPoints,subProjData));
			}
		} catch (JSONException e) {
			e.printStackTrace();
			ToastShow(getString(R.string.software_error));
		}
	}
}